<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>最大子数组和 - 算法详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #2d2d2d;
            padding: 12px 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .code-dots {
            display: flex;
            gap: 8px;
        }
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .dot-red { background: #ff5f56; }
        .dot-yellow { background: #ffbd2e; }
        .dot-green { background: #27c93f; }
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
        }
        code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            color: #d4d4d4;
            line-height: 1.6;
        }
        .keyword { color: #c586c0; }
        .function { color: #dcdcaa; }
        .number { color: #b5cea8; }
        .string { color: #ce9178; }
        .comment { color: #6a9955; }
        .operator { color: #d4d4d4; }
        .variable { color: #9cdcfe; }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.6s ease-out;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .first-letter::first-letter {
            font-size: 3.5rem;
            font-weight: 700;
            float: left;
            line-height: 1;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">最大子数组和</h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                探索动态规划的优雅之美，用 Kadane 算法解决经典问题
            </p>
            <div class="mt-10 flex justify-center gap-6">
                <div class="bg-white bg-opacity-20 backdrop-blur-sm rounded-lg px-6 py-3">
                    <i class="fas fa-clock mr-2"></i>
                    <span>时间复杂度 O(n)</span>
                </div>
                <div class="bg-white bg-opacity-20 backdrop-blur-sm rounded-lg px-6 py-3">
                    <i class="fas fa-memory mr-2"></i>
                    <span>空间复杂度 O(1)</span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-16">
        <!-- Problem Description -->
        <section class="mb-16 animate-fadeInUp">
            <div class="bg-white rounded-2xl shadow-lg p-8 md:p-12 card-hover">
                <h2 class="text-3xl font-bold mb-6 flex items-center">
                    <i class="fas fa-puzzle-piece mr-3 text-purple-600"></i>
                    <span>题目描述</span>
                </h2>
                <p class="text-lg leading-relaxed text-gray-700 first-letter">
                    给定一个整数数组，找出一个具有最大和的连续子数组（至少包含一个元素）。例如，给定数组 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">[-2, 1, -3, 4, -1, 2, 1, -5, 4]</code>，连续子数组 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">[4, -1, 2, 1]</code> 的和最大，为 6。
                </p>
                
                <!-- Visual Example -->
                <div class="mt-8 bg-gradient-to-r from-purple-50 to-pink-50 rounded-xl p-6">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">
                        <i class="fas fa-chart-line mr-2 text-purple-600"></i>
                        示例数组分析
                    </h3>
                    <div class="flex flex-wrap gap-2 justify-center">
                        <span class="bg-red-100 text-red-700 px-4 py-2 rounded-lg font-mono">-2</span>
                        <span class="bg-green-100 text-green-700 px-4 py-2 rounded-lg font-mono">1</span>
                        <span class="bg-red-100 text-red-700 px-4 py-2 rounded-lg font-mono">-3</span>
                        <span class="bg-purple-200 text-purple-800 px-4 py-2 rounded-lg font-mono font-bold border-2 border-purple-600">4</span>
                        <span class="bg-purple-200 text-purple-800 px-4 py-2 rounded-lg font-mono font-bold border-2 border-purple-600">-1</span>
                        <span class="bg-purple-200 text-purple-800 px-4 py-2 rounded-lg font-mono font-bold border-2 border-purple-600">2</span>
                        <span class="bg-purple-200 text-purple-800 px-4 py-2 rounded-lg font-mono font-bold border-2 border-purple-600">1</span>
                        <span class="bg-red-100 text-red-700 px-4 py-2 rounded-lg font-mono">-5</span>
                        <span class="bg-green-100 text-green-700 px-4 py-2 rounded-lg font-mono">4</span>
                    </div>
                    <p class="text-center mt-4 text-gray-600">
                        最大子数组和：<span class="text-2xl font-bold text-purple-600">6</span>
                    </p>
                </div>
            </div>
        </section>

        <!-- Core Concepts -->
        <section class="mb-16 animate-fadeInUp" style="animation-delay: 0.2s;">
            <div class="bg-white rounded-2xl shadow-lg p-8 md:p-12 card-hover">
                <h2 class="text-3xl font-bold mb-6 flex items-center">
                    <i class="fas fa-brain mr-3 text-purple-600"></i>
                    <span>核心考点</span>
                </h2>
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="bg-gradient-to-br from-purple-50 to-purple-100 rounded-xl p-6 text-center card-hover">
                        <i class="fas fa-project-diagram text-4xl text-purple-600 mb-4"></i>
                        <h3 class="text-xl font-semibold mb-2">动态规划</h3>
                        <p class="text-gray-600">通过子问题的最优解构建整体最优解</p>
                    </div>
                    <div class="bg-gradient-to-br from-pink-50 to-pink-100 rounded-xl p-6 text-center card-hover">
                        <i class="fas fa-code text-4xl text-pink-600 mb-4"></i>
                        <h3 class="text-xl font-semibold mb-2">Kadane 算法</h3>
                        <p class="text-gray-600">线性时间复杂度的经典算法</p>
                    </div>
                    <div class="bg-gradient-to-br from-indigo-50 to-indigo-100 rounded-xl p-6 text-center card-hover">
                        <i class="fas fa-window-restore text-4xl text-indigo-600 mb-4"></i>
                        <h3 class="text-xl font-semibold mb-2">滑动窗口思想</h3>
                        <p class="text-gray-600">动态调整子数组边界寻找最优解</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Algorithm Visualization -->
        <section class="mb-16 animate-fadeInUp" style="animation-delay: 0.4s;">
            <div class="bg-white rounded-2xl shadow-lg p-8 md:p-12">
                <h2 class="text-3xl font-bold mb-6 flex items-center">
                    <i class="fas fa-sitemap mr-3 text-purple-600"></i>
                    <span>算法流程图</span>
                </h2>
                <div class="mermaid">
                    graph TD
                        A[开始] --> B[初始化 curr_sum = max_sum = nums[0]]
                        B --> C{遍历数组}
                        C --> D[curr_sum = max(num, curr_sum + num)]
                        D --> E[max_sum = max(max_sum, curr_sum)]
                        E --> F{是否遍历完成?}
                        F -->|否| C
                        F -->|是| G[返回 max_sum]
                        G --> H[结束]
                        
                        style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style H fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style D fill:#f9a8d4,stroke:#ec4899,stroke-width:2px
                        style E fill:#f9a8d4,stroke:#ec4899,stroke-width:2px
                </div>
            </div>
        </section>

        <!-- Solution Approaches -->
        <section class="mb-16 animate-fadeInUp" style="animation-delay: 0.6s;">
            <div class="bg-white rounded-2xl shadow-lg p-8 md:p-12">
                <h2 class="text-3xl font-bold mb-8 flex items-center">
                    <i class="fas fa-lightbulb mr-3 text-purple-600"></i>
                    <span>解题思路</span>
                </h2>
                
                <!-- Kadane Algorithm -->
                <div class="mb-10">
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <span class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3 text-sm">1</span>
                        Kadane 算法
                    </h3>
                    <div class="bg-gradient-to-r from-purple-50 to-pink-50 rounded-xl p-6">
                        <p class="text-lg leading-relaxed mb-4">
                            维护一个变量 <code class="bg-white px-2 py-1 rounded shadow-sm">curr_sum</code> 表示当前子数组的和，另一个变量 <code class="bg-white px-2 py-1 rounded shadow-sm">max_sum</code> 记录最大子数组和。
                        </p>
                        <p class="text-lg leading-relaxed mb-4">
                            遍历数组时，<code class="bg-white px-2 py-1 rounded shadow-sm">curr_sum = max(nums[i], curr_sum + nums[i])</code>，并更新 <code class="bg-white px-2 py-1 rounded shadow-sm">max_sum = max(max_sum, curr_sum)</code>。
                        </p>
                        <div class="flex gap-4 mt-6">
                            <div class="bg-white rounded-lg px-4 py-2 shadow-sm">
                                <i class="fas fa-clock text-purple-600 mr-2"></i>
                                时间复杂度：O(n)
                            </div>
                            <div class="bg-white rounded-lg px-4 py-2 shadow-sm">
                                <i class="fas fa-memory text-purple-600 mr-2"></i>
                                空间复杂度：O(1)
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Dynamic Programming -->
                <div>
                    <h3 class="text-2xl font-semibold mb-4 